import {Injectable} from "@angular/core";
import {HttpClient} from "@angular/common/http";
import {Award, UserInfo, Winning} from "./domain";

@Injectable()
export class AwardService {
  private apiUrl="http://www.zm-it.cn/v1/";
  constructor(private http:HttpClient){}
  getjiang(){
    return this.http.get<Winning[]>("http://www.zm-it.cn/v1/winning");
  }
  getAwards(){
    return this.http.get<Award[]>("http://www.zm-it.cn/v1/award");
  }
  award(id:number){
     return this.http.get<Award>(this.apiUrl+"award/"+id);
  }
  acc(id:number){
    return this.http.get<Award>(this.apiUrl+"award/"+id);
  }
  baa(id:number){
    return this.http.get<Award>(this.apiUrl+"award/"+id);
  }
  prize(id:number){
    return this.http.get<{}>(this.apiUrl+"prize/"+id);
  }
  infos(award:number){
    let op:any={
      params:{
        status:"ATTENDED",
        page:1,
        size:100,
        award:award
      }
    };
    return this.http.get<{}>(this.apiUrl+"winning",op)
  }
  users(ids:string[]){
    return this.http.get<UserInfo[]>(this.apiUrl+"userInfo",{
      params:{
        openid:ids
      }
    });
  }
  getyong(){
    return this.http.get<UserInfo[]>(this.apiUrl+"wxmpUser");
  }

  annoucePrize(id:number,once:boolean){
    let op:any={
      params:{
        prize:id,
        once:once
      }
    };
    return this.http.put(this.apiUrl+"winning",null,op)
  }
}
